package com.xindaoapp.henghua.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.xindaoapp.henghua.GloableParams;
import com.xindaoapp.henghua.R;
import com.xindaoapp.henghua.entry.PropertyGatherInfo;
import com.xindaoapp.henghua.fragment.DetailFragment;
import com.xindaoapp.henghua.fragment.LabelFragment;
import com.xindaoapp.henghua.fragment.PhotoFragment;
import com.xindaoapp.henghua.manager.UIManager;

/**
 * 标签详情
 * @author Administrator
 *
 */
public class LabelDetailsActivity extends BaseActivity implements OnClickListener {
	private Button detail, label, photo;
	private DetailFragment detailFragment;
	private LabelFragment labelFragment;
	private PhotoFragment photoFragment;
	private TextView tvTitle;

	private Fragment currentF;

	/** 获取设备相关所有信息*/
	private PropertyGatherInfo info = null;

	Bundle lableDetailBundle = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_label_details);
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);// 隐藏键盘

		lableDetailBundle = getIntent().getExtras();
		info = (PropertyGatherInfo) lableDetailBundle.getSerializable("info");

		detail = (Button) findViewById(R.id.side_detail);
		label = (Button) findViewById(R.id.side_label);
		photo = (Button) findViewById(R.id.side_photo);

		tvTitle = getTvTitle();

		detail.setOnClickListener(this);
		label.setOnClickListener(this);
		photo.setOnClickListener(this);

		detail.setBackgroundResource(getImageId(0, true));

		init();
	}

	@Override
	protected void onStart() {
		super.onStart();
		if (info != null) {
			tvTitle.setText(info.name);
		}
	}

	private void init() {
		GloableParams.MAIN = this;
//		tv_download.setVisibility(View.GONE);

		detailFragment = DetailFragment.newInstance(lableDetailBundle);
		labelFragment = LabelFragment.newInstance(lableDetailBundle);
		photoFragment = PhotoFragment.newInstance(lableDetailBundle);

		UIManager.getInstance().addFragment(detailFragment, false, null);
		currentF = detailFragment;
	}

//	private void addDetail() {
//		UIManager.getInstance().addFragment(detailFragment, false, null);
//		currentF = detailFragment;
//	}
//	private void addLabel() {
//		UIManager.getInstance().changeFragment(labelFragment, false, null);
//	}
//
//	private void addPhoto() {
//		UIManager.getInstance().changeFragment(photoFragment, false, null);
//	}

	/**
	 * 通过状态显示图片状态
	 * 
	 * @param paramInt
	 * @param paramBoolean
	 *            图片状态
	 * @return
	 */
	private int getImageId(int paramInt, boolean paramBoolean) {
		switch (paramInt) {
		default:
			return -1;
		case 0:
			if (paramBoolean)
				return R.drawable.side_detail_press;
			return R.drawable.side_detail;
		case 1:
			if (paramBoolean)
				return R.drawable.side_label_press;
			return R.drawable.side_label;
		case 2:
			if (paramBoolean)
				return R.drawable.side_photo_press;
			return R.drawable.side_photo;
		}
	}

	@Override
	public void onClick(View v) {
		detail.setBackgroundResource(getImageId(0, false));
		label.setBackgroundResource(getImageId(1, false));
		photo.setBackgroundResource(getImageId(2, false));
		switch (v.getId()) {
		case R.id.side_detail:
			detail.setBackgroundResource(getImageId(0, true));
//			addDetail();

			if (currentF != detailFragment) {
				UIManager.getInstance().switchContent(currentF, detailFragment);
				currentF = detailFragment;
			}

			break;
		case R.id.side_label:
			label.setBackgroundResource(getImageId(1, true));
//			addLabel();

			if (currentF != labelFragment) {
				UIManager.getInstance().switchContent(currentF, labelFragment);
				currentF = labelFragment;
			}

			break;
		case R.id.side_photo:
			photo.setBackgroundResource(getImageId(2, true));
//			addPhoto();

			if (currentF != photoFragment) {
				UIManager.getInstance().switchContent(currentF, photoFragment);
				currentF = photoFragment;
			}

			break;
		default:
			break;
		}
	}

	@Override
	String getTabTitle() {
		return "";
	}

	@Override
	protected boolean onShowDownloadButton() {
		return false;
	}

}
